package com.qdc.datacenters.domain.vo.rule;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.Date;

/**
 * @author danmo
 * @date 2024-03-18 10:25
 **/
@Schema
@Data
public class GroupTimeoutListVo {

    @Schema(description = "主键id")
    private Long id;

    @Schema(description = "规则ID")
    private Long ruleId;

    @Schema(description = "规则名称")
    private String ruleName;

    @Schema(description = "客户ID")
    private String customerId;

    @Schema(description = "客户名称")
    private String customerName;

    @Schema(description = "群主ID")
    private String userId;
    @Schema(description = "群主名称")
    private String userName;

    @Schema(description = "群聊ID")
    private String chatId;
    @Schema(description = "群聊名称")
    private String chatName;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "触发时间")
    private Date sendTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "回复时间")
    private Date replyTime;

    @Schema(description = "超时时长")
    private String timeOut;

    public String getTimeOut() {
        long between = DateUtil.between(this.sendTime, this.replyTime, DateUnit.SECOND);
        long hours = between / 3600;            //转换小时
        between = between % 3600;                //剩余秒数
        long minutes = between / 60;            //转换分钟
        between = between % 60;                //剩余秒数
        if (hours > 0) {
            return  hours + "h" + minutes + "m" + between + "s";
        } else {
            return  minutes + "m" + between + "s";
        }
    }
}
